#!/bin/sh

# chkconfig: 345 10 90
# description: tomcat6 service

function START_TOMCAT(){
        if [[ $(ps aux|grep "java"|grep -v "grep") != "" ]];then
                echo -e "\033[32mTomcat6\033[0m has been running..."
        else
                /srv/tomcat6/bin/catalina.sh start
        fi
#funciton end
}

function STOP_TOMCAT(){
        if [[ $(ps aux|grep "java"|grep -v "grep") != "" ]];then
                /srv/tomcat6/bin/catalina.sh stop
        else
                echo -e "\033[32mTomcat6\033[0m has been not run."
        fi
#funciton end
}

function RESTART_TOMCAT(){
        /srv/tomcat6/bin/catalina.sh stop
        /srv/tomcat6/bin/catalina.sh start
#funciton end
}

case $1 in
        start)
                START_TOMCAT
                ;;
        stop)
                STOP_TOMCAT
                ;;
        restart)
                RESTART_TOMCAT
                ;;
        status)
                if [[ $(ps aux|grep "java"|grep -v "grep") != "" ]];then
                        echo -e "\033[32mTomcat6\033[0m has been running..."
                else
                        echo -e "\033[32mTomcat6\033[0m is stop."
                fi
                ;;
        *)
                echo -e $"Useage: $0 {\033[32mstart\033[0m|\033[32mstop\033[0m|\033[32mrestart\033[0m}"
                exit 2
                ;;
esac
